import { createRouter, createWebHistory } from 'vue-router';
import LocationTable from '../views/LocationTable.vue';
import LocationDetail from '../views/LocationDetail.vue';
import RecordDetail from '../views/RecordDetail.vue'; // 新增的记录详情组件
import MapView from '../views/MapView.vue';
import UserUpload from '../components/UserUpLoadPage/UserUpLoad.vue'  // 添加导入
import SingleUploadDetail from '../components/UserUpLoadPage/SingleUploadDetail.vue'
import TopicDisplay from '@/components/TopicDisplay.vue';


// 创建一个临时的空白组件用于未实现的页面
const NotImplemented = {
  template: `
    <div class="not-implemented">
      <h2>功能开发中...</h2>
      <p>该功能正在开发中，敬请期待！</p>
    </div>
  `,
  name: 'NotImplemented'
};

const routes = [
  {
    path: '/',
    redirect: '/map'  // 保持原有的重定向
  },
  // 原有的路由
  {
    path: '/locations',
    name: 'LocationTable',
    component: LocationTable
  },
  {
    path: '/locations/:id',
    name: 'LocationDetail',
    component: LocationDetail,
  },
  {
    path: '/record/:record_id',
    name: 'RecordDetail',
    component: RecordDetail
  },
  // 新增的路由
  {
    path: '/creator',
    name: 'Creator',
    component: NotImplemented
  },
  {
    path: '/map',
    name: 'Map',
    component: MapView
  },
  {
    path: '/display',
    name: 'Display',
    component: TopicDisplay
  },
  {
    path: '/user',
    name: 'User',
    component: NotImplemented
  },
  {
    path: '/upload',
    name: 'UserUpload',
    component: UserUpload
  },
  {
    path: '/upload/detail/:id',
    name: 'UploadDetail',
    component: SingleUploadDetail
  },
  // 404页面路由
  {
    path: '/:pathMatch(.*)*',
    redirect: '/locations'  // 将所有未匹配的路由重定向到位置列表
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes,
  // 可选：设置激活链接的类名
  linkActiveClass: 'router-link-active',
  linkExactActiveClass: 'router-link-exact-active',
});

// 可选：添加全局导航守卫
router.beforeEach((to, from, next) => {
  // 可以在这里添加导航守卫逻辑
  // 例如：修改页面标题
  document.title = to.name ? `${to.name} - 古迹文物数字地图` : '古迹文物数字地图';
  next();
});

export default router;